const config = require('../config');

module.exports = function(req,res,next){
    if(req.session.token){
        var timeDifference = new Date().getTime() - req.session.updateTime;
        if(timeDifference<config.sessionTime){
            req.session.updateTime = new Date().getTime();
            next();
        }else{
            req.session.destroy();
            res.redirect('/login');
        }
    }else{
        res.redirect('/login');
    }
};